Fix `this.memory(key, falsy)`

Akinori MUSHA 8 years ago
parent
commit
806722b4f8
1 changed files with 4 additions and 7 deletions
  1. 4 7
      app/models/agents/java_script_agent.rb

+ 4 - 7
app/models/agents/java_script_agent.rb

@@ -114,12 +114,9 @@ module Agents
114 114
       context["getOptions"] = lambda { |a, x| interpolated.to_json }
115 115
       context["doLog"] = lambda { |a, x| log x }
116 116
       context["doError"] = lambda { |a, x| error x }
117
-      context["getMemory"] = lambda do |a, x, y|
118
-        if x && y
119
-          memory[x] = clean_nans(y)
120
-        else
121
-          memory.to_json
122
-        end
117
+      context["getMemory"] = lambda { |a| memory.to_json }
118
+      context["setMemory"] = lambda do |a, x, y|
119
+        memory[x] = clean_nans(y)
123 120
       end
124 121
       context["deleteKey"] = lambda { |a, x| memory.delete(x).to_json }
125 122
       context["escapeHtml"] = lambda { |a, x| CGI.escapeHTML(x) }
@@ -168,7 +165,7 @@ module Agents
168 165
 
169 166
         Agent.memory = function(key, value) {
170 167
           if (typeof(key) !== "undefined" && typeof(value) !== "undefined") {
171
-            getMemory(key, value);
168
+            setMemory(key, value);
172 169
           } else if (typeof(key) !== "undefined") {
173 170
             return JSON.parse(getMemory())[key];
174 171
           } else {